using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VFSRASTER
    {
        public DataRow Convert2FSRASTER(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryFSRASTER(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["FSRMANDANT"] = " ".PadRight(2 ); 
         dwReturn["FSRGRRAS"] = " ".PadRight(3 ); 
         dwReturn["FSRAENZL"] = " ".PadRight(0 ); 
         dwReturn["FSRAENB"] = " ".PadRight(8 ); 
         dwReturn["FSRAEND"] = " ".PadRight(0 ); 
         dwReturn["FSRNEUB"] = " ".PadRight(8 ); 
         dwReturn["FSRNEUD"] = " ".PadRight(0 ); 
         dwReturn["FSRGROE1"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE2"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE3"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE4"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE5"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE6"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE7"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE8"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE9"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE10"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE11"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE12"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE13"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE14"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE15"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE16"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE17"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE18"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE19"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE20"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE21"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE22"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE23"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE24"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE25"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE26"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE27"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE28"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE29"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE30"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE31"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE32"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE33"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE34"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE35"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE36"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE37"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE38"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE39"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE40"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE41"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE42"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE43"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE44"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE45"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE46"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE47"] = " ".PadRight(7 ); 
         dwReturn["FSRGROE48"] = " ".PadRight(7 ); 
         dwReturn["FSRBGROE"] = " ".PadRight(7 ); 
         dwReturn["FSRFILLER"] = " ".PadRight(26 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapFSRASTER(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveFSRASTER(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryFSRASTER(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapFSRASTER(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertFSRASTER(dwLocal, ITXDBVERSION);
            }
            UpdateFSRASTER(dwLocal);
        }
        public void InsertFSRASTER(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO FSRASTER(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryFSRASTER(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM FSRASTER WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM FSRASTER  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "FSRASTER";
            Return = Result;
            return Return;
        }
        public void DeleteFSRASTER(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM FSRASTER   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateFSRASTER(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE FSRASTER SET "
                    +"FSRMANDANT= :FSRMANDANT,"
                    +"FSRGRRAS= :FSRGRRAS,"
                    +"FSRAENZL= :FSRAENZL,"
                    +"FSRAENB= :FSRAENB,"
                    +"FSRAEND= :FSRAEND,"
                    +"FSRNEUB= :FSRNEUB,"
                    +"FSRNEUD= :FSRNEUD,"
                    +"FSRGROE1= :FSRGROE1,"
                    +"FSRGROE2= :FSRGROE2,"
                    +"FSRGROE3= :FSRGROE3,"
                    +"FSRGROE4= :FSRGROE4,"
                    +"FSRGROE5= :FSRGROE5,"
                    +"FSRGROE6= :FSRGROE6,"
                    +"FSRGROE7= :FSRGROE7,"
                    +"FSRGROE8= :FSRGROE8,"
                    +"FSRGROE9= :FSRGROE9,"
                    +"FSRGROE10= :FSRGROE10,"
                    +"FSRGROE11= :FSRGROE11,"
                    +"FSRGROE12= :FSRGROE12,"
                    +"FSRGROE13= :FSRGROE13,"
                    +"FSRGROE14= :FSRGROE14,"
                    +"FSRGROE15= :FSRGROE15,"
                    +"FSRGROE16= :FSRGROE16,"
                    +"FSRGROE17= :FSRGROE17,"
                    +"FSRGROE18= :FSRGROE18,"
                    +"FSRGROE19= :FSRGROE19,"
                    +"FSRGROE20= :FSRGROE20,"
                    +"FSRGROE21= :FSRGROE21,"
                    +"FSRGROE22= :FSRGROE22,"
                    +"FSRGROE23= :FSRGROE23,"
                    +"FSRGROE24= :FSRGROE24,"
                    +"FSRGROE25= :FSRGROE25,"
                    +"FSRGROE26= :FSRGROE26,"
                    +"FSRGROE27= :FSRGROE27,"
                    +"FSRGROE28= :FSRGROE28,"
                    +"FSRGROE29= :FSRGROE29,"
                    +"FSRGROE30= :FSRGROE30,"
                    +"FSRGROE31= :FSRGROE31,"
                    +"FSRGROE32= :FSRGROE32,"
                    +"FSRGROE33= :FSRGROE33,"
                    +"FSRGROE34= :FSRGROE34,"
                    +"FSRGROE35= :FSRGROE35,"
                    +"FSRGROE36= :FSRGROE36,"
                    +"FSRGROE37= :FSRGROE37,"
                    +"FSRGROE38= :FSRGROE38,"
                    +"FSRGROE39= :FSRGROE39,"
                    +"FSRGROE40= :FSRGROE40,"
                    +"FSRGROE41= :FSRGROE41,"
                    +"FSRGROE42= :FSRGROE42,"
                    +"FSRGROE43= :FSRGROE43,"
                    +"FSRGROE44= :FSRGROE44,"
                    +"FSRGROE45= :FSRGROE45,"
                    +"FSRGROE46= :FSRGROE46,"
                    +"FSRGROE47= :FSRGROE47,"
                    +"FSRGROE48= :FSRGROE48,"
                    +"FSRBGROE= :FSRBGROE,"
                    +"FSRFILLER= :FSRFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("FSRMANDANT", OracleType.NVarChar).Value = dwData["FSRMANDANT"].ToString(); 
          or1.Parameters.Add("FSRGRRAS", OracleType.NVarChar).Value = dwData["FSRGRRAS"].ToString(); 
          or1.Parameters.Add("FSRAENZL", OracleType.NVarChar).Value = dwData["FSRAENZL"].ToString(); 
          or1.Parameters.Add("FSRAENB", OracleType.NVarChar).Value = dwData["FSRAENB"].ToString(); 
          or1.Parameters.Add("FSRAEND", OracleType.NVarChar).Value = dwData["FSRAEND"].ToString(); 
          or1.Parameters.Add("FSRNEUB", OracleType.NVarChar).Value = dwData["FSRNEUB"].ToString(); 
          or1.Parameters.Add("FSRNEUD", OracleType.NVarChar).Value = dwData["FSRNEUD"].ToString(); 
          or1.Parameters.Add("FSRGROE1", OracleType.NVarChar).Value = dwData["FSRGROE1"].ToString(); 
          or1.Parameters.Add("FSRGROE2", OracleType.NVarChar).Value = dwData["FSRGROE2"].ToString(); 
          or1.Parameters.Add("FSRGROE3", OracleType.NVarChar).Value = dwData["FSRGROE3"].ToString(); 
          or1.Parameters.Add("FSRGROE4", OracleType.NVarChar).Value = dwData["FSRGROE4"].ToString(); 
          or1.Parameters.Add("FSRGROE5", OracleType.NVarChar).Value = dwData["FSRGROE5"].ToString(); 
          or1.Parameters.Add("FSRGROE6", OracleType.NVarChar).Value = dwData["FSRGROE6"].ToString(); 
          or1.Parameters.Add("FSRGROE7", OracleType.NVarChar).Value = dwData["FSRGROE7"].ToString(); 
          or1.Parameters.Add("FSRGROE8", OracleType.NVarChar).Value = dwData["FSRGROE8"].ToString(); 
          or1.Parameters.Add("FSRGROE9", OracleType.NVarChar).Value = dwData["FSRGROE9"].ToString(); 
          or1.Parameters.Add("FSRGROE10", OracleType.NVarChar).Value = dwData["FSRGROE10"].ToString(); 
          or1.Parameters.Add("FSRGROE11", OracleType.NVarChar).Value = dwData["FSRGROE11"].ToString(); 
          or1.Parameters.Add("FSRGROE12", OracleType.NVarChar).Value = dwData["FSRGROE12"].ToString(); 
          or1.Parameters.Add("FSRGROE13", OracleType.NVarChar).Value = dwData["FSRGROE13"].ToString(); 
          or1.Parameters.Add("FSRGROE14", OracleType.NVarChar).Value = dwData["FSRGROE14"].ToString(); 
          or1.Parameters.Add("FSRGROE15", OracleType.NVarChar).Value = dwData["FSRGROE15"].ToString(); 
          or1.Parameters.Add("FSRGROE16", OracleType.NVarChar).Value = dwData["FSRGROE16"].ToString(); 
          or1.Parameters.Add("FSRGROE17", OracleType.NVarChar).Value = dwData["FSRGROE17"].ToString(); 
          or1.Parameters.Add("FSRGROE18", OracleType.NVarChar).Value = dwData["FSRGROE18"].ToString(); 
          or1.Parameters.Add("FSRGROE19", OracleType.NVarChar).Value = dwData["FSRGROE19"].ToString(); 
          or1.Parameters.Add("FSRGROE20", OracleType.NVarChar).Value = dwData["FSRGROE20"].ToString(); 
          or1.Parameters.Add("FSRGROE21", OracleType.NVarChar).Value = dwData["FSRGROE21"].ToString(); 
          or1.Parameters.Add("FSRGROE22", OracleType.NVarChar).Value = dwData["FSRGROE22"].ToString(); 
          or1.Parameters.Add("FSRGROE23", OracleType.NVarChar).Value = dwData["FSRGROE23"].ToString(); 
          or1.Parameters.Add("FSRGROE24", OracleType.NVarChar).Value = dwData["FSRGROE24"].ToString(); 
          or1.Parameters.Add("FSRGROE25", OracleType.NVarChar).Value = dwData["FSRGROE25"].ToString(); 
          or1.Parameters.Add("FSRGROE26", OracleType.NVarChar).Value = dwData["FSRGROE26"].ToString(); 
          or1.Parameters.Add("FSRGROE27", OracleType.NVarChar).Value = dwData["FSRGROE27"].ToString(); 
          or1.Parameters.Add("FSRGROE28", OracleType.NVarChar).Value = dwData["FSRGROE28"].ToString(); 
          or1.Parameters.Add("FSRGROE29", OracleType.NVarChar).Value = dwData["FSRGROE29"].ToString(); 
          or1.Parameters.Add("FSRGROE30", OracleType.NVarChar).Value = dwData["FSRGROE30"].ToString(); 
          or1.Parameters.Add("FSRGROE31", OracleType.NVarChar).Value = dwData["FSRGROE31"].ToString(); 
          or1.Parameters.Add("FSRGROE32", OracleType.NVarChar).Value = dwData["FSRGROE32"].ToString(); 
          or1.Parameters.Add("FSRGROE33", OracleType.NVarChar).Value = dwData["FSRGROE33"].ToString(); 
          or1.Parameters.Add("FSRGROE34", OracleType.NVarChar).Value = dwData["FSRGROE34"].ToString(); 
          or1.Parameters.Add("FSRGROE35", OracleType.NVarChar).Value = dwData["FSRGROE35"].ToString(); 
          or1.Parameters.Add("FSRGROE36", OracleType.NVarChar).Value = dwData["FSRGROE36"].ToString(); 
          or1.Parameters.Add("FSRGROE37", OracleType.NVarChar).Value = dwData["FSRGROE37"].ToString(); 
          or1.Parameters.Add("FSRGROE38", OracleType.NVarChar).Value = dwData["FSRGROE38"].ToString(); 
          or1.Parameters.Add("FSRGROE39", OracleType.NVarChar).Value = dwData["FSRGROE39"].ToString(); 
          or1.Parameters.Add("FSRGROE40", OracleType.NVarChar).Value = dwData["FSRGROE40"].ToString(); 
          or1.Parameters.Add("FSRGROE41", OracleType.NVarChar).Value = dwData["FSRGROE41"].ToString(); 
          or1.Parameters.Add("FSRGROE42", OracleType.NVarChar).Value = dwData["FSRGROE42"].ToString(); 
          or1.Parameters.Add("FSRGROE43", OracleType.NVarChar).Value = dwData["FSRGROE43"].ToString(); 
          or1.Parameters.Add("FSRGROE44", OracleType.NVarChar).Value = dwData["FSRGROE44"].ToString(); 
          or1.Parameters.Add("FSRGROE45", OracleType.NVarChar).Value = dwData["FSRGROE45"].ToString(); 
          or1.Parameters.Add("FSRGROE46", OracleType.NVarChar).Value = dwData["FSRGROE46"].ToString(); 
          or1.Parameters.Add("FSRGROE47", OracleType.NVarChar).Value = dwData["FSRGROE47"].ToString(); 
          or1.Parameters.Add("FSRGROE48", OracleType.NVarChar).Value = dwData["FSRGROE48"].ToString(); 
          or1.Parameters.Add("FSRBGROE", OracleType.NVarChar).Value = dwData["FSRBGROE"].ToString(); 
          or1.Parameters.Add("FSRFILLER", OracleType.NVarChar).Value = dwData["FSRFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
